home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / WINER.ZIP / SWAPMEM.ASM < prev    next >
Assembly Source File  |  1992-05-13  |  881b  |  29 lines

  1. ;********* SWAPMEM.ASM, swaps two sections of memory
  2.  
  3. ;Copyright (c) 1991 Ethan Winer
  4.  
  5.  
  6. .Model Medium, Basic
  7. .Code
  8.  
  9. SwapMem Proc Uses SI DI DS ES, Var1:DWord, Var2:DWord, NumBytes:Word
  10.  
  11.     Lds  SI,Var1        ;get the segmented address of the first variable
  12.     Les  DI,Var2        ;and for the second variable too
  13.     Mov  CX,NumBytes    ;get the number of bytes to exchange
  14.     Jcxz Exit           ;we can't swap zero bytes!
  15.     Cld                 ;ensure Lodsb works forward
  16.  
  17. DoSwap:
  18.     Mov  AL,ES:[DI]     ;get a byte from the second variable
  19.     Xchg AL,[SI]        ;swap it with the first variable
  20.     Stosb               ;complete the swap and also increment DI
  21.     Inc  SI             ;point to the next byte in the first variable
  22.     Loop DoSwap         ;continue until done
  23.  
  24. Exit:
  25.     Ret                 ;return to BASIC
  26.  
  27. SwapMem Endp
  28. End
  29.